package cn.crism.blog.controller;

import cn.crism.blog.entity.Blogroll;
import cn.crism.blog.service.BlogrollService;
import cn.crism.blog.util.ResultVOUtil;
import cn.crism.blog.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author: Crism
 * @Date: 上午9:31 18/2/12
 * @Description:
 */

@RestController
@RequestMapping("/api/bg")
public class BlogrollController {
    @Autowired
    private BlogrollService blogrollService;

    @PostMapping("/createBlogroll")
    public ResultVO createBlogroll(@RequestBody @Valid Blogroll blogroll){
        return blogrollService.createBlogroll(blogroll)?ResultVOUtil.success("添加成功！"):ResultVOUtil.error(1,"添加失败！");
    }

    @PostMapping("/modifyBlogroll")
    public ResultVO modifyBlogroll(@RequestBody @Valid Blogroll blogroll){
        return blogrollService.modifyBlogroll(blogroll)?ResultVOUtil.success("修改成功！"):ResultVOUtil.error(1,"修改失败！");
    }

    @PostMapping("/removeBlogroll")
    public ResultVO removeBlogroll(@RequestBody @Valid Blogroll blogroll){
        return blogrollService.removeBlogroll(blogroll.getBlogId())?ResultVOUtil.success("删除成功！"):ResultVOUtil.error(1,"删除失败！");
    }

    @GetMapping("/getBlogrolls")
    public ResultVO getBlogrolls(){
        List<Blogroll> blogrolls = blogrollService.getBlogrolls();
        return blogrolls!=null ? ResultVOUtil.success(blogrolls):ResultVOUtil.error(1,"获取失败！");
    }
}
